#pragma once
#include <QObject>
#include <QString>
#include <QVariantMap>
#include <QQueue>
#include <QMutex>
#include <QDebug>
#include <QTimer>
#include <RayCiPro_C.h>
#include"../BeamQuality/BeamQualityTypes.h"

// 电机类型枚举
enum class MotorType {
    Device_Motor_Default,
    Device_Motor_FuYu,
    Device_B,
    Device_C,
};

// 电机状态枚举
enum class MotorStatus {
    Disconnected,
    Connected,
    Moving,
    Stopped,
    Homing,
    Error
};


// 运动模式枚举
enum class MotionMode {
    Relative= 1,  // 相对运动
    Absolute=2 // 绝对运动

};

// 回零方向枚举
enum class HomeDirection {
    Positive=1,  // 正向回零
    Negative=2   // 反向回零
};

// 停止模式枚举
enum class StopMode {
    Decelerate=1, // 减速停止
    Immediate=2     // 立即停止
};

class Device_Motor : public QObject {
    Q_OBJECT
    friend class Motor_Control_Panel;
public:
    explicit Device_Motor(MotorType type, QObject* parent = nullptr);
    virtual ~Device_Motor();
    virtual bool Connect() = 0;
    virtual bool Disconnect() = 0;
    virtual bool MoveTo(double position, MotionMode mode = MotionMode::Absolute) = 0;
    virtual double GetPosition() = 0;
    virtual bool Home(HomeDirection direction = HomeDirection::Negative) = 0;

    virtual bool Stop(StopMode mode = StopMode::Decelerate);
    virtual bool SetSpeed(double speed);
    virtual bool SetAcceleration(double acc);
    virtual bool SetDeceleration(double dec);
    virtual double GetSpeed();
    virtual bool IsMoving();
    virtual MotorStatus GetStatus();

    MotorType GetMotorType() const { return m_type; }
    bool IsConnected() const { return m_connected; }
    void SetStatus(MotorStatus status);
    void setScantimer(double scantimer);


signals:
    void ConnectionStatusChanged(bool connected);
    void StatusChanged(MotorStatus status);
    void ErrorOccurred(const QString& error);
    void OperationCompleted(const QString& operation);
    void positionUpdated(double position);



protected:
    MotorType m_type;
    bool m_connected = false;
    MotorStatus m_status = MotorStatus::Disconnected;
    double m_currentSpeed = 0.0;
    double m_maxSpeed = 100.0;
    double m_acceleration = 0.0;
    double m_deceleration = 0.0;


    double scantimer=100;
    QVector<ScanDataPoint> m_scanData=QVector<ScanDataPoint>();

    void SetError(const QString& error);


};